package org.zero.controller;

import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.zero.model.User;
import org.zero.service.UserService;

/**
 * @author Zero (cnzeropro@qq.com)
 * @date 2021/10/26 11:55
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @GetMapping("/get/{id}")
    public String getUser(@PathVariable int id, Model model) {
        User user = userService.getById(id);
        System.out.println(user);

        // 模拟服务器内部发生错误
        // int i = 1 / 0;

        model.addAttribute("user", user);

        return "user";
    }
}
